package com.linyaonan.leetcode.medium._2130;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Lin
 * @date: 2024/3/4
 */
public class MaximumTwinSumOfALinkedList {

    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public int pairSum(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }

        int max = -1;
        for (int i = 0; i < list.size() / 2; i++) {
            max = Math.max(max, (list.get(i) + list.get(list.size() - i - 1)));
        }

        return max;

    }

}
